package com.itqf.service.impl;

import com.itqf.bean.Permission;
import com.itqf.bean.User;
import com.itqf.mapper.PermissionMapper;
import com.itqf.mapper.UserMapper;
import com.itqf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * projectName: rbac2103
 *
 * @author: 赵伟风
 * time: 2021/7/8 11:47
 * description:
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public Map login(User user) {

        //1.处理参数
        //2.调用数据库
        User userNew = userMapper.query(user);

        Map map = new HashMap();
        if (userNew == null) {
            map.put("code", 0);
            return  map;
        }

        List<Permission> permissions =  permissionMapper.query(userNew.getuId());
        //3.处理返回值
        map.put("code", 1);
        map.put("user", userNew);
        map.put("permission", permissions);
        return map;
    }
}
